<?
global $db,$user;
if (!$params["id"]) { $e = inc_incfile("wiki/global.php",$params); }
else $e = $params;
$link = $e["link"];

skin_param("title","Comments");


if ($_POST["content"]) {
	$db->autoquery("insert","wikicomment",array(
		"link"=>$link,
		"datetimeon"=>date("Y-m-d H:i:s"),
		"users_id"=>$user["id"],
		"content"=>$_POST["content"],
		));
	}

echo "<form method=post>";
echo "<textarea name='content' rows=5 cols=80></textarea><br>";
echo "<input type='submit' value='Continue'>";
echo "</form>";

$r = $db->query("select wikicomment.*, users.title as users_title from wikicomment ".
	" left join users on users.id = wikicomment.users_id ".
	" where link = ".$db->sqlstring($link).
	" order by datetimeon desc ".
	"");
/*
$n=0;
foreach ($r as $e) {
	if (!$e["users_title"]) $e["users_title"] = "Anonymous";
	if ($n) echo "<hr>";
	echo "<div><b>".date("F j, Y g:ia",strtotime($e["datetimeon"]));
	echo " - {$e["users_title"]}</b></div>";
	#echo "<div>".str_replace("\n","<br>",htmlentities($e["content"]))."</div>";
	echo "<pre>".htmlentities($e["content"])."</pre>";
	$n++;
	}
*/
	echo "<table class='comments'>";
	
	if (!count($r)) {
		echo "<tr><th>No users comments have been submitted.";
		}
		
	$n=0;
	foreach ($r as $e) {
		if (!$e["users_title"]) $e["users_title"] = "Anonymous";
		#if ($n) echo "<hr>";
		echo "<tr><th>".date("F j, Y g:ia",strtotime($e["datetimeon"]));
		echo " - ".htmlentities($e["users_title"]);
		echo "<tr><td><pre>".htmlentities($e["content"])."</pre>";
		$n++;
		}
	echo "</table>";

?>